unit uCadastroDependente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uCadastroGenerico, dxSkinsCore, dxSkinsdxBarPainter, dxSkinBlack,
  dxSkinBlue, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer,
  cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxCalendar, cxDBEdit,
  StdCtrls, DBCtrls, Mask, ZSequence, DB, ZAbstractRODataset, ZAbstractDataset,
  ZAbstractTable, ZDataset, dxBar, cxClasses, ActnList, ImgList, ExtCtrls,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver ;

type
  TfCadastroDependente = class(TfCadastroGenerico)
    pnl2: TPanel;
    gbTitular: TGroupBox;
    lblCodTitular: TLabel;
    lblCPFTitular: TLabel;
    lblNomeTitular: TLabel;
    lblRGTitular: TLabel;
    dbedtCodigoTitular: TDBEdit;
    dbedtCPFTitular: TDBEdit;
    dbedtNomeTitular: TDBEdit;
    dbedtRGTitular: TDBEdit;
    gbDadosDependente: TGroupBox;
    lblDepedente: TLabel;
    lblCPFDependente: TLabel;
    lblNomeDependente: TLabel;
    lblSexo: TLabel;
    lblDataNascimento: TLabel;
    lblParentesco: TLabel;
    lblStatus: TLabel;
    lblObservacao: TLabel;
    dbedtCPFDependente: TDBEdit;
    dbedtCodigoDependente: TDBEdit;
    dbedtNomeDependente: TDBEdit;
    dbcbbSexo: TDBComboBox;
    dbedtParentesco: TDBEdit;
    dbedtStatus: TDBEdit;
    dbmmoObservacao: TDBMemo;
    dbcalEditDataNascimento: TcxDBDateEdit;
    dsTitular: TDataSource;
    procedure actAdicionarExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure actGravarExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fCadastroDependente: TfCadastroDependente;

implementation

uses uDataModule;

{$R *.dfm}

procedure TfCadastroDependente.actAdicionarExecute(Sender: TObject);
begin
  inherited;
    dbedtCodigoDependente.ReadOnly := False;
    dbedtStatus.ReadOnly := False;
    tblCadastro.FieldByName('cod_dependente').value :=  seqCadastro.GetNextValue;
    dbedtCodigoDependente.Text := tblCadastro.FieldByName('cod_dependente').AsString;
    dbedtStatus.Text := 'ATIVO';
    dbedtCodigoDependente.ReadOnly := True;
    dbedtStatus.ReadOnly := True;
end;

procedure TfCadastroDependente.actGravarExecute(Sender: TObject);
begin
  tblCadastro.FieldByName('cod_cliente').AsString := dbedtCodigoTitular.Text;
  inherited;
  DataModule1.tblDependentes.Refresh;
end;

procedure TfCadastroDependente.FormShow(Sender: TObject);
begin
  inherited;
    if Modo <> MCEdita then
  begin
    dbedtCodigoDependente.ReadOnly := false;
    tblCadastro.FieldByName('cod_dependente').value :=  seqCadastro.GetNextValue;
    dbedtCodigoDependente.Text := tblCadastro.FieldByName('cod_dependente').AsString;
    dbedtCodigoDependente.ReadOnly := True;
    dbedtStatus.Text := 'ATIVO';
    dbedtStatus.ReadOnly := True;
  end;
end;

end.
